<?php
error_reporting( E_ALL&~E_NOTICE );
ini_set( 'display_errors', 'off' );//屏蔽错误和警告提示
include("../mysql.php");
if(isset($_POST['key']) and isset($_POST['value']) and isset($_POST['adminpwd']))
{
if($_POST['adminpwd']!="dashen"){
    //echo "无权操作";
    exit;
}    
$key=$_POST['key'];
$value=$_POST['value'];



$check="SELECT * FROM `wabaos` WHERE `key` = '$key' AND `value` = '$value'";
$ret=mysql_query($check);
$row=mysql_fetch_array($ret);
if($row["value"]){
    echo "操作失败，已经有该条数据了";
    exit;
}
$check="SELECT * FROM `wabaos` WHERE `key` = '$key'";
$ret=mysql_query($check);
$row=mysql_fetch_array($ret);
if($row["value"]){
    $old_value=$row["value"];
    if($value!=$old_value){
        $mysql="UPDATE `wabaos` SET `value` = '$value' WHERE `key` ='$key' and `value` ='$old_value';";
        mysql_query($mysql);
    }
    exit;
}
$sql="alter table `wabaos` AUTO_INCREMENT=1";
mysql_query($sql);  //序列号自动归1
$mysql="INSERT INTO `wabaos` (`id`, `key`, `value`) VALUES (NULL, '$key', '$value');";
mysql_query($mysql);
echo "新增成功一条数据为:[$key,$value]";
}
else{
    echo "无权访问";
}
?>